package huxibianjie.com.lbscandroid.task;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import huxibianjie.com.lbscandroid.util.MyLog;
import retrofit2.Call;
import retrofit2.Response;

/**
 * 说点什么
 * Created by CZF on 2018/7/23.
 */
public abstract class Callback<T> implements retrofit2.Callback<T> {
    @Override
    public final void onResponse(Call<T> call, Response<T> response) {
        if (response.code() == 200) {
            onSuccess(response.body());
        } else {
            onFailure("似乎已断开互联网的连接");
        }
    }

    @Override
    public final void onFailure(Call<T> call, Throwable t) {
        MyLog.e("task", t.getMessage());
        if (t instanceof ResultException) {
            onFailure(t.getMessage());
        } else {
            onFailure("似乎已断开互联网的连接");
        }
    }

    public abstract void onSuccess(@Nullable T t);

    public abstract void onFailure(@NonNull String error);
}